package com.nbjtjc.safe.api.sys;

import com.nbjtjc.common.validator.ValidatorUtils;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.sys.SysDutyMapper;
import com.nbjtjc.safe.model.sys.SysDuty;
import com.nbjtjc.safe.model.sys.SysDutyPublic;
import com.nbjtjc.safe.service.sys.SysDutyService;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @auther guqianbin
 * @date 2018/7/23 16:01
 * 值班
 **/
@RestController
@CrossOrigin("*")
@RequestMapping("/sysDuty")
public class SysDutyController {

    @Autowired
    private SysDutyService sysDutyService;

    @Autowired
    private SysDutyMapper sysDutyMapper;

    @PostMapping("/add")
    public Result add(SysDuty sysDuty){
        Result result=new Result();
        result.setData(sysDutyService.add(sysDuty));
        return result;
    }

    @PostMapping("/update")
    public Result update(SysDuty sysDuty){
        Result result=new Result();
        sysDuty.setWriteTime(new Date());
        sysDutyMapper.updateByPrimaryKeySelective(sysDuty);
        result.setData(sysDuty);
        return result;
    }

    @PostMapping("/find")
    public Result find(SysDuty sysDuty){
        Result result=new Result();
        result.setData(sysDutyService.find(sysDuty));
        return result;
    }

    @GetMapping("/delete/{id}")
    public Result delete(@PathVariable("id") int sysDutyId){
        Result result=new Result();
        sysDutyMapper.deleteByPrimaryKey(sysDutyId);
        return result;
    }

    @PostMapping("/getPublicDuty")
    public Result getPublicDuty(SysDuty sysDuty){
        Result result=new Result();
        result.setData(sysDutyService.getPublicDuty(sysDuty));
        return result;
    }

    @PostMapping("/getDutyByType")
    public Result getDutyByType(SysDuty sysDuty,int year){
        Result result=new Result();
        result.setData(sysDutyService.getDutyByType(sysDuty,year));
        return result;
    }
}
